<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>更新学生</title>
</head>
<body>
<form>
    <table border="1">
        <tr><td colspan="2"><h1>更新学生内容</h1></td></tr>
        <tr>
            <td>学生编号</td>
            <td>
                    <span id="id_txt"></span><input type="hidden" id="id" name="id"/>
            </td>
        </tr>
        <tr>
            <td>学生姓名</td>
            <td>
                    <input type="text" id="sname" name="sname"/>
            </td>
        </tr>
        <tr>
            <td>生日</td>
            <td>
                    <input type="text" id="birthday" name="birthday"/>
            </td>
        </tr>
        <tr>
            <td>性别</td>
            <td>
                    <input type="text" id="gender" name="gender"/>
            </td>
        </tr>
        <tr>
            <td>电话</td>
            <td>
                    <input type="text" id="telephone" name="telephone"/>
            </td>
        </tr>
        <tr>
            <td>邮箱</td>
            <td>
                    <input type="text" id="email" name="email"/>
            </td>
        </tr>
        <tr>
            <td>班级编号</td>
            <td>
                    <input type="text" id="classid" name="classid"/>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" id="tijiao" value="提交"/>
                <input type="reset" value="重置"/>
            </td>
        </tr>
    </table>
</form>
<script src="/js/jquery-1.12.4.js"></script>
    <script>
    var param = location.href.substring(location.href.indexOf('?')+1);
    $.getJSON("/student/findById.json",param,function(detail){
        $("#id_txt").text(detail.id);
        $("#id").val(detail.id);
        $("#sname").val(detail.sname);
        $("#birthday").val(detail.birthday);
        $("#gender").val(detail.gender);
        $("#telephone").val(detail.telephone);
        $("#email").val(detail.email);
        $("#classid").val(detail.classid);
    });
    //点击提交按钮
    $("#tijiao").click(function(){
        if(!$("#sname").val()){
            alert("学生姓名不能为空");
            return;
        }
        if(!$("#birthday").val()){
            alert("生日不能为空");
            return;
        }
        if(!$("#gender").val()){
            alert("性别不能为空");
            return;
        }
        if(!$("#telephone").val()){
            alert("电话不能为空");
            return;
        }
        if(!$("#email").val()){
            alert("邮箱不能为空");
            return;
        }
        if(!$("#classid").val()){
            alert("班级编号不能为空");
            return;
        }
        
        $.post("/student/update.json",$("form").serialize(),function(result){
            if(result.flag==true){
                alert(result.msg);
                location.href="/admin/student/list.html";
            }else{
                alert(result.msg);
            }
        })

    })
</script>

</body>
</html>